package com.xuecheng.content.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Mq交换机与队列配置
 */
@Configuration
public class MQConfiguration {
    // 创建交换机
    @Bean
    public TopicExchange contentExchange(){
        return new TopicExchange("content-exchange");
    }
    // 创建队列
    @Bean
    public Queue contentQueue(){
        return new Queue("content.queue");
    }

    //创建下架队列
    @Bean
    public Queue contentOfflineQueue(){
        return new Queue("content.queue.offline");
    }

    // 完成绑定
    @Bean
    public Binding bindingContentQueueToContentExchange(TopicExchange contentExchange, Queue contentQueue){
        return BindingBuilder.bind(contentQueue).to(contentExchange).with("course.pub");
    }

    //绑定下架队列
    @Bean
    public Binding bindingContentOfflineToContentExchange(TopicExchange contentExchange,Queue contentOfflineQueue){
        return BindingBuilder.bind(contentOfflineQueue).to(contentExchange).with("course.offline");
    }
}
